package com.cjjd.c.feature.home.shoping.evaluate;

import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.subscribe.HotelCommentShowModel;
import com.cjjd.c.utils.ImageUtil;
import com.cjjd.c.utils.PhoneUtil;
import com.google.android.flexbox.FlexboxLayout;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ----------------------------------
 * Created by xyd on 2017/9/28.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class EvaluateAdapter extends MyBaseAdapter {


    public EvaluateAdapter(FragmentActivity mContext) {
        super(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_evaluate, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        HotelCommentShowModel itemData = (HotelCommentShowModel) getItem(position);
        ImageUtil.displayImage(itemData.customerPicPath, viewHolder.ivUserLogo);
        viewHolder.tvUserName.setText(itemData.customerName);
        viewHolder.tv_time.setText(itemData.dateTime);
        viewHolder.ratingBar.setNumStars(itemData.getScore());
        viewHolder.tvEvaluateContent.setText(itemData.commnet);

        for (int i = 0; i < itemData.picList.size(); i++) {
            ImageView imageView = new ImageView(mContext);
            ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(PhoneUtil.dip2px(80),PhoneUtil.dip2px(80));
            imageView.setLayoutParams(layoutParams);
            ImageUtil.displayImage(itemData.picList.get(i), imageView);
            viewHolder.llEvaluatePic.addView(imageView, i);
        }

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.iv_user_logo)
        ImageView ivUserLogo;
        @Bind(R.id.tv_user_name)
        TextView tvUserName;
        @Bind(R.id.tv_time)
        TextView tv_time;

        @Bind(R.id.ratingBar)
        RatingBar ratingBar;
        @Bind(R.id.tv_evaluate_content)
        TextView tvEvaluateContent;
        @Bind(R.id.ll_evaluate_pic)
        FlexboxLayout llEvaluatePic;
        @Bind(R.id.iv_praise)
        ImageView ivPraise;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
